package com.example.selfservicestation.extensions

import android.util.Base64
import java.lang.StringBuilder

fun String.phoneMask() : String {
    if (length == 11) {
        return "${substring(0, 3)}****${substring(7)}"
    }
    return this
}

fun String.isInt() : Boolean {
    return try {
        toInt()
        true
    } catch (e: Exception) {
        false
    }
}

fun String.decodeBase64() : String {
    return String(Base64.decode(toByteArray(), Base64.NO_WRAP))
}

fun String.isPhone() : Boolean {
    if (length != 11) return false
    return matches(Regex("[1234567890]{11}"))
}

fun String.times(count: Int) : String {
    if (count > 1) {
        val sb = StringBuilder()
        for (i in 0 until count) {
            sb.append(this)
        }
        return sb.toString()
    }
    return this
}

val TEL_REGEX = Regex("1[3-9]\\d{9}")
fun String.isMobile() =  if (length != 11) false else this.matches(TEL_REGEX)